import json, sys, array
from datetime import datetime

if len(sys.argv) < 2:
    print "enter json file"
    sys.exit(0)
    
f = open(sys.argv[1]);
players = json.loads(f.read())

print "Number of players: %d" % len(players) 

levelsCount = array.array('I', [0,0,0,0,0,0,0,0,0,0,0,0,0,0])
resetsCount = array.array('I', [0,0,0,0,0,0,0,0,0,0,0,0,0,0])
timeCount = array.array('I', [0,0,0,0,0,0,0,0,0,0,0,0,0,0])
maxLevel = 0

for player in players: 

    # print ""
    # print "Player: %s" % player['uid']
    # print "\tPage loads: %d" % len(player['pageloads'])
    # print "\tLevels logged: %d" % len(player['levels'])
	
	# Avoid outliers, like us testing on different machines...
    if len(player['levels']) < 100 and len(player['levels']) > 0 and datetime.fromtimestamp(player['levels'][0]['log_q_ts']) > datetime(2012,6,2):
    
        levels = player['levels']
        for level in levels:
            actions = level['actions']
            idx = level['qid']
            
            while len(timeCount) <= idx:
                timeCount.append(0)
            while len(resetsCount) <= idx:
                resetsCount.append(0)
            while len(levelsCount) <= idx:
                levelsCount.append(0)
            
            if len(actions) > 0 and idx < 21:
                levelsCount[idx] += 1
            
                x = ""
                y = ""
                w = ""
                h = ""
                
                for action in actions:
                    strs = action['a_detail'].split(",")
                    for str in strs:
                        subsplit = str.split(":");
            
                    # if (subsplit[0] == "{\"Reset Count\"" or subsplit[0] == "\"Reset Count\""):
                    #    resetsCount[idx] += int(subsplit[1].split("}")[0])
                    
                    # if (subsplit[0] == "{\"Elapsed Time\"" or subsplit[0] == "\"Elapsed Time\""):
                    #    print "time"
                    #    timeCount[idx] += int(subsplit[1].split("}")[0])
                    #else:
                    #    timeCount[idx] += 60 * int(subsplit[1].split("\"")[1]) + int(subsplit[2].split("\"")[0])
for i in range(1,21):
    print "%d,%d" % (i,levelsCount[i])